#!/bin/bash
#by lingci
#2017/06/09
#paste Qball.dat Qfall.dat Energy.dat Qnormall.dat |awk '{printf ("%8i  %6.3f  %6.3f  %10.7f  %10.7f  %10.7f  %10.7f  %6.3f\n",$1,$2,$4,$5,$6,$7,$8,$10)}'>kankan.dat
# awk '{print $1}' transition.list> frameNumber.dat
#while read i
#do
#awk -v line=$i 'NR==line {print}' kankan.dat >> EncounterState.dat
#done<frameNumber.dat
#============Prontein-RNA interaction Energy
#encounter state
awk '$2>0.0 && $2<=0.4 && $3>=0.0 && $3<1.5 {print $4}' kankan.dat > Coul-SR-buf2.dat
awk '$2>0.0 && $2<=0.4 && $3>=0.0 && $3<1.5 {print $5}' kankan.dat > LJ-SR-buf2.dat
awk '$2>0.0 && $2<=0.4 && $3>=0.0 && $3<1.5 {print $6}' kankan.dat > Coul-14-buf2.dat
awk '$2>0.0 && $2<=0.4 && $3>=0.0 && $3<1.5 {print $7}' kankan.dat > LJ-14-buf2.dat
#unbound state
awk '$2==0.0 {print $4}' kankan.dat > Coul-SR-ub1.dat
awk '$2==0.0 {print $5}' kankan.dat > LJ-SR-ub1.dat
awk '$2==0.0 {print $6}' kankan.dat > Coul-14-ub1.dat
awk '$2==0.0 {print $7}' kankan.dat > LJ-14-ub1.dat
#bound state
awk '$2>0.7  && $3>0.5  {print $4}' kankan.dat > Coul-SR-bf3.dat
awk '$2>0.7  && $3>0.5  {print $5}' kankan.dat > LJ-SR-bf3.dat
awk '$2>0.7  && $3>0.5  {print $6}' kankan.dat > Coul-14-bf3.dat
awk '$2>0.7  && $3>0.5  {print $7}' kankan.dat > LJ-14-bf3.dat
#calculate expectation
echo "====bound state======"
echo "Elect,native: "
awk '{x[NR]=$1;s+=$1;n++}END{a=s/n;for (i in x){ss+=(x[i]-a)^2} sd=sqrt(ss/n);print "Ave="a " SD="sd}' Coul-14-bf3.dat
echo "Elect,non-native: "
awk '{x[NR]=$1;s+=$1;n++}END{a=s/n;for (i in x){ss+=(x[i]-a)^2} sd=sqrt(ss/n);print "Ave="a " SD="sd}' Coul-SR-bf3.dat
echo "LJ,native: "
awk '{x[NR]=$1;s+=$1;n++}END{a=s/n;for (i in x){ss+=(x[i]-a)^2} sd=sqrt(ss/n);print "Ave="a " SD="sd}' LJ-14-bf3.dat
echo "LJ,non-native: "
awk '{x[NR]=$1;s+=$1;n++}END{a=s/n;for (i in x){ss+=(x[i]-a)^2} sd=sqrt(ss/n);print "Ave="a " SD="sd}' LJ-SR-bf3.dat
echo "====encounter state======"
echo "Elect,native: "
awk '{x[NR]=$1;s+=$1;n++}END{a=s/n;for (i in x){ss+=(x[i]-a)^2} sd=sqrt(ss/n);print "Ave="a " SD="sd}' Coul-14-buf2.dat
echo "Elect,non-native: "
awk '{x[NR]=$1;s+=$1;n++}END{a=s/n;for (i in x){ss+=(x[i]-a)^2} sd=sqrt(ss/n);print "Ave="a " SD="sd}' Coul-SR-buf2.dat
echo "LJ,native: "
awk '{x[NR]=$1;s+=$1;n++}END{a=s/n;for (i in x){ss+=(x[i]-a)^2} sd=sqrt(ss/n);print "Ave="a " SD="sd}' LJ-14-buf2.dat
echo "LJ,non-native: "
awk '{x[NR]=$1;s+=$1;n++}END{a=s/n;for (i in x){ss+=(x[i]-a)^2} sd=sqrt(ss/n);print "Ave="a " SD="sd}' LJ-SR-buf2.dat
echo "====unbound state======"
echo "Elect,native: "
awk '{x[NR]=$1;s+=$1;n++}END{a=s/n;for (i in x){ss+=(x[i]-a)^2} sd=sqrt(ss/n);print "Ave="a " SD="sd}' Coul-14-ub1.dat
echo "Elect,non-native: "
awk '{x[NR]=$1;s+=$1;n++}END{a=s/n;for (i in x){ss+=(x[i]-a)^2} sd=sqrt(ss/n);print "Ave="a " SD="sd}' Coul-SR-ub1.dat
echo "LJ,native: "
awk '{x[NR]=$1;s+=$1;n++}END{a=s/n;for (i in x){ss+=(x[i]-a)^2} sd=sqrt(ss/n);print "Ave="a " SD="sd}' LJ-14-ub1.dat
echo "LJ,non-native: "
awk '{x[NR]=$1;s+=$1;n++}END{a=s/n;for (i in x){ss+=(x[i]-a)^2} sd=sqrt(ss/n);print "Ave="a " SD="sd}' LJ-SR-ub1.dat
